<?php
require_once ROOT_LIBRARY_UTILITY.DS. 'BaseModel.php';
require_once ROOT_APPLICATION_MODULE_BACKEND_MODELS.DS. 'Model_Article_Type.php';

class Model_Article extends BaseModel{

    public function  __construct() {
        parent::__construct();
        $this->_key = 'id';
        $this->_tableName = 'articles';
    }

    public function getDataForPagination($where)
    {
        try
        {
            return $this->_db->select()
                    ->from('articles')
                    ->order('id DESC')
                    ->where($where);
        }
        catch(Zend_Db_Exception $ex)
        {
            throw new Exception($ex);
        }
    }

    public function getAllByArticleId($id)
    {
        try
        {
            $data = array();
            $mdArticleType = new Model_Article_Type();
            $articleTypes = $mdArticleType->_getAll(" parent_id = $id ");

            if(count($articleTypes) > 0)
            {
                foreach($articleTypes as $item)
                {
                    array_push($data, $this->_getAll(" article_types_id = $item->id "));
                    $this->getAllByArticleId($item->id);
                }
                
            }

            return $data;
        }
        catch(Zend_Db_Exception $ex)
        {
            throw new Exception($ex);
        }
    }
}
?>
